package com.rf.richfitwheel.workflow.conf;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;

import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    //声明队列
    @Bean
    public Queue systemQueue() {
        return new Queue("workflow.system", true); // true表示持久化该队列
    }
    @Bean
    public Queue creditGrantingQueue() {
        return new Queue("workflow.creditGranting", true); // true表示持久化该队列
    }

    @Bean
    public Queue financingQueue() {
        return new Queue("workflow.financing", true);
    }

    @Bean
    public Queue financingProQueue() {
        return new Queue("workflow.financingPro", true);
    }

    @Bean
    public Queue AccountMngQueue() {
        return new Queue("workflow.accountMng", true);
    }

    @Bean
    public Queue finDerivativesQueue() {
        return new Queue("workflow.finDerivatives", true);
    }

    @Bean
    public Queue crmQueue() {
        return new Queue("workflow.crm", true);
    }
    @Bean
    public Queue evaModelQueue() {
        return new Queue("workflow.evamodel", true);
    }


    @Bean
    public Queue guaranteeQueue() {
        return new Queue("workflow.guarantee", true);
    }

    @Bean
    public Queue capitalBudgetQueue() {
        return new Queue("workflow.capitalBudget", true);
    }
    @Bean
    public Queue settlementQueue() {
        return new Queue("workflow.settlement", true);
    }
    @Bean
    public Queue settlementWarnLogAndSubmitTaskQueue() {
        return new Queue("workflow.settlement.warnLogAndSubmitTask", true);
    }
    @Bean
    public Queue settlementMergeBsInstructionQueue() {
        return new Queue("workflow.settlement.mergeBsInstruction", true);
    }
    @Bean
    public Queue settlementToBePayCommitQueue() {
        return new Queue("workflow.settlement.toBePayCommit", true);
    }
    @Bean
    public Queue fundSettlementQueue() {
        return new Queue("workflow.fundSettlement", true);
    }
    @Bean
    public Queue financingDebtQueue(){ return new Queue("workflow.financingDebt",true);}


    //声明交互器
    @Bean
    TopicExchange workflowTopicExchange() {
        return new TopicExchange("workflowTopicExchange");
    }

    //绑定
    @Bean
    public Binding bindingSystem() {
        return BindingBuilder.bind(systemQueue()).to(workflowTopicExchange()).with("workflow.system");
    }

    //绑定
    @Bean
    public Binding bindingCreditGranting() {
        return BindingBuilder.bind(creditGrantingQueue()).to(workflowTopicExchange()).with("workflow.creditGranting");
    }


    //绑定
    @Bean
    public Binding bindingFinancing() {
        return BindingBuilder.bind(financingQueue()).to(workflowTopicExchange()).with("workflow.financing");
    }

    //绑定
    @Bean
    public Binding bindingFinancingPro() {
        return BindingBuilder.bind(financingProQueue()).to(workflowTopicExchange()).with("workflow.financingPro");
    }

    //绑定
    @Bean
    public Binding bindingAccountMng() {
        return BindingBuilder.bind(AccountMngQueue()).to(workflowTopicExchange()).with("workflow.accountMng");
    }

    //绑定
    @Bean
    public Binding bindingFinDerivatives() {
        return BindingBuilder.bind(finDerivativesQueue()).to(workflowTopicExchange()).with("workflow.finDerivatives");
    }

    //绑定
    @Bean
    public Binding bindingCrm() {
        return BindingBuilder.bind(crmQueue()).to(workflowTopicExchange()).with("workflow.crm");
    }

    @Bean
    public Binding bindingReceive() {
        return BindingBuilder.bind(crmQueue()).to(workflowTopicExchange()).with("workflow.receivemng");
    }

    //绑定
    @Bean
    public Binding bindingEvaModel() {
        return BindingBuilder.bind(evaModelQueue()).to(workflowTopicExchange()).with("workflow.evamodel");
    }
    //绑定
    @Bean
    public Binding bindingGuarantee() {
        return BindingBuilder.bind(guaranteeQueue()).to(workflowTopicExchange()).with("workflow.guarantee");
    }
    //绑定
    @Bean
    public Binding bindingCapitalBudget() {
        return BindingBuilder.bind(capitalBudgetQueue()).to(workflowTopicExchange()).with("workflow.capitalBudget");
    }
    @Bean
    public Binding bindingSettlement() {
        return BindingBuilder.bind(settlementQueue()).to(workflowTopicExchange()).with("workflow.settlement");
    }
    @Bean
    public Binding bindingSettlementWarnLogAndSubmitTask() {
        return BindingBuilder.bind(settlementWarnLogAndSubmitTaskQueue()).to(workflowTopicExchange()).with("workflow.settlement.warnLogAndSubmitTask");
    }
    @Bean
    public Binding bindingSettlementMergeBsInstruction() {
        return BindingBuilder.bind(settlementMergeBsInstructionQueue()).to(workflowTopicExchange()).with("workflow.settlement.mergeBsInstruction");
    }
    @Bean
    public Binding bindingSettlementToBePayCommit() {
        return BindingBuilder.bind(settlementToBePayCommitQueue()).to(workflowTopicExchange()).with("workflow.settlement.toBePayCommit");
    }
    @Bean
    public Binding bindingFundSettlement() {
        return BindingBuilder.bind(fundSettlementQueue()).to(workflowTopicExchange()).with("workflow.fundSettlement");
    }

    @Bean
    public Binding bindingFinancingDebt(){
        return BindingBuilder.bind(financingDebtQueue()).to(workflowTopicExchange()).with("workflow.financingDebt");
    }
    /**
     * 定义消息转换实例
     *
     * @return
     */
    @Bean
    MessageConverter jackson2JsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }


}